package com.jixiang.tracedata.util;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

/**
 * @author quanbiao
 * @date 2018-08-28
 */
public class XmlToBean {

    public static <T> T toBean(Class<T> clazz, String xml) {
        try {
            XStream xstream = new XStream(new DomDriver());
            xstream.processAnnotations(clazz);
            xstream.autodetectAnnotations(true);
            xstream.setClassLoader(clazz.getClassLoader());
            return (T) xstream.fromXML(xml);
        } catch (Exception e) {
            throw e;
        }
    }

}
